package com.oss.controller.oss;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oss.common.BaseResponse;
import com.oss.dto.oss.DeleteByIdDto;
import com.oss.dto.oss.capitalmanage.CapitalManageAddDto;
import com.oss.dto.oss.capitalmanage.CapitalManageImportDto;
import com.oss.dto.oss.capitalmanage.CapitalManagePageDto;
import com.oss.dto.oss.capitalmanage.CapitalManageUpdateDto;
import com.oss.dto.oss.trademanage.TradeManageGetByIDDto;
import com.oss.entity.oss.CapitalManage;
import com.oss.service.oss.CapitalManageService;
import com.oss.vo.oss.capital.CapitalManageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;

/**
 * 资金管理
 */
@RestController
@RequestMapping("/capitalManage")
public class CapitalManageController {
    @Autowired
    CapitalManageService capitalManageService;

    @PostMapping("/selectByPage")
    public BaseResponse<IPage<CapitalManageVO>> selectByPage(@RequestBody @Valid CapitalManagePageDto dto){
        return BaseResponse.success(capitalManageService.selectByPage(dto));
    }
    @PostMapping("/getByID")
    public BaseResponse<CapitalManageVO> getByID(@RequestBody @Valid TradeManageGetByIDDto dto){
        CapitalManageVO vo = new CapitalManageVO();
        CapitalManage entity = capitalManageService.getById(dto.getId());
        BeanUtils.copyProperties(entity, vo);
        vo.setInoutFlag(String.valueOf(entity.getInoutFlag()));
        return BaseResponse.success(vo);
    }
    @PostMapping("/add")
    public BaseResponse<String> add(@RequestBody @Valid CapitalManageAddDto dto){
        return BaseResponse.success(capitalManageService.add(dto));
    }
    @PostMapping("/update")
    public BaseResponse<String> updateData(@RequestBody @Valid CapitalManageUpdateDto dto){
        return BaseResponse.success(capitalManageService.updateData(dto));
    }
    @PostMapping("/delete")
    public BaseResponse<String> delete(@RequestBody @Valid DeleteByIdDto dto){
        return BaseResponse.success(capitalManageService.delete(dto));
    }
    @PostMapping("/import")
    public BaseResponse<String> importData(@RequestBody @Valid CapitalManageImportDto dto){
        return BaseResponse.success(capitalManageService.importData(dto));
    }
}